﻿<%@ Page Language="VB" MasterPageFile="~/Default.master" Title="New Member Registration" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<%@ Register Src="~/UserControls/Photos_formpicker.ascx" TagName="Photos_formpicker" TagPrefix="Club" %>

<%@ Import Namespace="SubSonic" %>
<%@ Import Namespace="ClubStarterKit.Data" %>

<script runat="server">
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        username.Enabled = False
        password.Enabled = False
        confirmpassword.Enabled = False
        email.Enabled = False
        question.Enabled = False
        answer.Enabled = False
        Addr.Enabled = False
        Phone.Enabled = False
        fname.Enabled = False
        lname.Enabled = False
        NewsletterCheck.Enabled = False
        If password.Text = confirmpassword.Text Then
            Try
                Membership.CreateUser(username.Text, password.Text, email.Text, question.Text, answer.Text, True, System.Web.Security.MembershipCreateStatus.Success)
                Dim user As MembershipUser = Membership.GetUser(username.Text)
                MemberInfo.Insert(Addr.Text, Phone.Text, fname.Text, lname.Text, Nothing, CType(user.ProviderUserKey, Guid), NewsletterCheck.Checked)
                Membership.UpdateUser(user)
                If ClubStarterKit.Web.UserAdministration.NeedsEmailVerification() = True Then
                    user.IsApproved = False
                    Membership.UpdateUser(user)
                    ClubStarterKit.Web.UserAdministration.SendEmailVer(user)
                    status.Text = "We have recieved your request. We have sent an email verification email. Please go to your email inbox and read the instructions from our email to verify your account."
                Else
                    If ClubStarterKit.Web.UserAdministration.NeedsAdminVerification() = True Then
                        user.IsApproved = False
                        Membership.UpdateUser(user)
                        ClubStarterKit.Web.UserAdministration.SendAdminVer(user)
                        status.Text = "We have recieved your request. Please wait while an administrator approves your membership application. You will recieve an email when your account is verified."
                    Else
                        user.IsApproved = True
                        Membership.UpdateUser(user)
                        FormsAuthentication.SetAuthCookie(user.UserName, False)
                        Response.Redirect("~/default.aspx")
                    End If
                End If
            Catch ex As Exception
                
            End Try
        Else
            status.Text = "Error. Your passwords do not match!"
            username.Enabled = True
            password.Enabled = True
            confirmpassword.Enabled = True
            email.Enabled = True
            question.Enabled = True
            answer.Enabled = True
            Addr.Enabled = True
            Phone.Enabled = True
            fname.Enabled = True
            lname.Enabled = True
            NewsletterCheck.Enabled = True
        End If
    End Sub
</script>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="body">
            <div class="fullwidth">
                <asp:ScriptManager id="ScriptManager1" runat="server">
                    </asp:ScriptManager><h2>
                    New user registration
                </h2>
                <div class="dashedline">
                </div>
                &nbsp;&nbsp;
                <br />
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                <table>
                    <tr>
                        <td style="width: 145px">
                            Username</td>
                        <td style="width: 210px">
                            <asp:TextBox ID="username" runat="server" Width="200px"></asp:TextBox></td>
                        <td style="width: 40px">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="username"
                                ErrorMessage="Please enter a username." ValidationGroup="reg">*</asp:RequiredFieldValidator></td>
                    </tr>
                    <tr>
                        <td style="width: 145px">
                            Password</td>
                        <td style="width: 210px">
                            <asp:TextBox ID="password" TextMode="Password" runat="server" Width="200px"></asp:TextBox></td>
                        <td style="width: 40px">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="password"
                                ErrorMessage="Please enter a password." ValidationGroup="reg">*</asp:RequiredFieldValidator></td>
                    </tr>
                    <tr>
                        <td style="width: 145px">
                            Confirm Password</td>
                        <td style="width: 210px">
                            <asp:TextBox ID="confirmpassword" TextMode="Password" runat="server" Width="200px"></asp:TextBox></td>
                        <td style="width: 40px">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="confirmpassword"
                                ErrorMessage="Please confirm your password." ValidationGroup="reg">*</asp:RequiredFieldValidator><asp:CompareValidator
                                    ID="CompareValidator1" runat="server" ControlToCompare="password" ControlToValidate="confirmpassword"
                                    ErrorMessage="Make sure your password and confirm password match." ValidationGroup="reg">*</asp:CompareValidator></td>
                    </tr>
                    <tr>
                        <td style="width: 145px">
                            Email</td>
                        <td style="width: 210px">
                            <asp:TextBox ID="email" runat="server" Width="200px"></asp:TextBox></td>
                        <td style="width: 40px">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="email"
                                ErrorMessage="Please enter an email address." ValidationGroup="reg">*</asp:RequiredFieldValidator><asp:RegularExpressionValidator
                                    ID="RegularExpressionValidator1" runat="server" ControlToValidate="email" ErrorMessage="Please enter a valid email address."
                                    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ValidationGroup="reg">*</asp:RegularExpressionValidator></td>
                    </tr>
                    <tr>
                        <td style="width: 145px">
                            Security Question</td>
                        <td style="width: 210px">
                            <asp:TextBox ID="question" runat="server" Width="200px"></asp:TextBox></td>
                        <td style="width: 40px">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="question"
                                ErrorMessage="Please enter a security question." ValidationGroup="reg">*</asp:RequiredFieldValidator></td>
                    </tr>
                    <tr>
                        <td style="width: 145px">
                            Security Answer</td>
                        <td style="width: 210px">
                            <asp:TextBox ID="answer" runat="server" Width="200px"></asp:TextBox></td>
                        <td style="width: 40px">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="answer"
                                ErrorMessage="Please enter a security answer." ValidationGroup="reg">*</asp:RequiredFieldValidator></td>
                    </tr>
                    <tr>
                        <td style="width: 145px">
                            First Name</td>
                        <td style="width: 210px">
                            <asp:TextBox ID="fname" runat="server" Width="200px"></asp:TextBox></td>
                        <td style="width: 40px">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="fname"
                                ErrorMessage="Please enter your first name." ValidationGroup="reg">*</asp:RequiredFieldValidator></td>
                    </tr>
                    <tr>
                        <td style="width: 145px">
                            Last Name</td>
                        <td style="width: 210px">
                            <asp:TextBox ID="lname" runat="server" Width="200px"></asp:TextBox></td>
                        <td style="width: 40px">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="lname"
                                ErrorMessage="Please enter your last name." ValidationGroup="reg">*</asp:RequiredFieldValidator></td>
                    </tr>
                    <tr>
                        <td style="width: 145px">
                            Address</td>
                        <td style="width: 210px">
                            <asp:TextBox ID="Addr" runat="server" Width="200px" Height="29px"></asp:TextBox></td>
                        <td style="width: 40px">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="Addr"
                                ErrorMessage="Please enter your address." ValidationGroup="reg">*</asp:RequiredFieldValidator></td>
                    </tr>
                    <tr>
                        <td style="width: 145px">
                            Phone</td>
                        <td style="width: 210px">
                            <asp:TextBox ID="Phone" runat="server" Width="200px" ValidationGroup="reg"></asp:TextBox></td>
                        <td style="width: 40px">

                        </td>
                    </tr>
                    <tr>
                        <td style="width: 145px">
                            Would you like to recieve the newsletter?</td>
                        <td style="width: 210px">
                            <asp:CheckBox ID="NewsletterCheck" runat="server" /></td>
                        <td style="width: 40px">
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="reg" />
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 145px">
                        </td>
                        <td style="width: 210px">
                            <Club:RolloverButton ID="Button1" runat="server" Text="Submit" ValidationGroup="reg" OnClick="Button1_Click" /></td>
                        <td style="width: 40px">
                        </td>
                    </tr>
                </table>
                <asp:Label ID="status" runat="server"></asp:Label>
                </ContentTemplate>
                </asp:UpdatePanel>
                <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="200">
                <ProgressTemplate>
                <asp:Image ID="loadingimg" runat="server" SkinID="loading" />
                </ProgressTemplate>
                </asp:UpdateProgress>
                <br />
                <br />
            </div>
        <div class="clear2column">
        </div>
    </div>
</asp:Content>
